# Author:Yiye
# -*- codeing = utf-8 -*-
# @Time :2021/11/11 16:43
# @Author:李卓
# @Site : 
# @File : redispool.py
# @Software : PyCharm
#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author:durant.zeng
@file:redisUtils.py
@time:2020/09/27
"""
import redis


class redisUtils:

    def __init__(self,host,port,password):
        '''
        初始化
        :param host:
        :param port:
        '''
        try:
            self.r = redis.StrictRedis(host=host,port=port,password=password,decode_responses=True)
        except Exception as e:
            print("redis连接失败,错误信息为%s" %e)

    def get_value(self,key):
        '''
        获取key的值
        :param key:
        :return:
        '''
        res = self.r.get(key)
        return res

    def get_ttl(self,key):
        '''
        获取key的过期时间
        :param key:
        :return:
        '''
        return self.r.ttl(key)


    def set_key_value(self,key,value):
        '''
        往redis中设值
        :param key:
        :param value:
        :return:
        '''
        self.r.set(key,value)

if __name__ == '__main__':
    r = redisUtils('47.94.155.194',6379,'java_redis_dev@password')
    r.set_key_value('counter',0)
